#include <iostream>
#include <pthread.h>

using namespace std;

class Mutex
{
public:
    Mutex(pthread_mutex_t *lock)
    {
        _lock = lock;
    }

    void lock()
    {
        pthread_mutex_lock(_lock);
    }

    void unlock()
    {
        pthread_mutex_unlock(_lock);
    }

private:
    pthread_mutex_t *_lock;
};

class lock_guard
{
public:
    lock_guard(pthread_mutex_t *lock)
    :_mutex(lock)
    {
        _mutex.lock();
    }

    ~lock_guard()
    {
        _mutex.unlock();
    }

private:
    Mutex _mutex;
};